package com.puhui.lib.utils

import android.util.Log
import com.puhui.lib.BuildConfig

object LogUtils {

    private const val TAG = "HttpLog"
    private const val SEPARATOR = "\n"

    private var allow: Boolean = BuildConfig.DEBUG

    /*******
     * 是否打印super log
     */
    private var isSuperLog = true

    private fun getPrefix(): String {
        return TAG
    }


    /*******************super log 带行号并且点击可跳转的log**************************/
    /*******************super log 带行号并且点击可跳转的log */
    /**
     * Send an INFO log message,绿色
     */
    fun printI(log: String) {
        if (allow && isSuperLog) {
            Log.i(TAG, log + SEPARATOR + callMethodAndLine())
        }
    }

    /**
     * Send a DEBUG log message,蓝色
     */
    fun printD(log: String) {
        if (allow && isSuperLog) {
            Log.d(TAG, log + SEPARATOR + callMethodAndLine())
        }
    }

    /**
     * Send an ERROR log message,红色
     */
    fun printE(log: String) {
        if (allow && isSuperLog) {
            Log.e(TAG, log + SEPARATOR + callMethodAndLine())
        }
    }

    /**
     * Send a VERBOSE log message,黑色/白色
     */
    fun printV(log: String) {
        if (allow && isSuperLog) {
            Log.v("TAG", log + SEPARATOR + callMethodAndLine())
        }
    }

    /**
     * Send a WARN log message,黄色
     */
    fun printW(log: String) {
        if (allow && isSuperLog) {
            Log.w(TAG, log + SEPARATOR + callMethodAndLine())
        }
    }

    private fun callMethodAndLine(): String {
        val result = StringBuilder("at ")
        val thisMethodStack = Exception().stackTrace[2]
        result.append(thisMethodStack.className + ".").append(thisMethodStack.methodName)
            .append("(" + thisMethodStack.fileName).append(
                ":" + thisMethodStack
                    .lineNumber + ")  "
            )
        return result.toString()
    }

}